package com.datastructure.stackandqueue;

import javax.lang.model.element.VariableElement;
import java.util.Stack;

/**
 * @author: 临晖
 * @date: 2023/10/19
 * @description:
 */
public class MyQueue {
    private Stack<Integer> stack01 = null;
    private Stack<Integer> stack02 = null;

    public MyQueue() {
        stack01 = new Stack<>();
        stack02 = new Stack<>();
    }

    public void push(int x) {
        stack01.push(x);
    }

    public int pop() {
        if (stack02.empty()) {
            stack01ToStack02();
        }
        Integer temp = stack02.pop();
        return temp;
    }

    public int peek() {
        //if (stack02.empty()) {
        //    stack01ToStack02();
        //}
        //
        //Integer ans = stack02.peek();
        ////stack02ToStack01();
        Integer ans = pop();
        stack01.push(ans);

        return ans;
    }

    public boolean empty() {
        return stack01.empty() && stack02.empty();
    }

    public void stack01ToStack02() {
        while (!stack01.empty()) {
            Integer num = stack01.pop();
            stack02.push(num);
        }
    }

    //public void stack02ToStack01() {
    //    while (!stack02.empty()) {
    //        Integer num = stack02.pop();
    //        stack01.push(num);
    //    }
    //}


}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.peek();
 * boolean param_4 = obj.empty();
 */
